<!DOCTYPE html>
<html>
<head>
    <title>参数编辑</title>
    {% include 'system/common/header.html' %}
</head>
<body>
    <form class="layui-form">
        <div class="mainBox">
            <div class="main-container">
                <div class="layui-form-item">
                    <input type="hidden" name="id" value="{{ software.id}}">
                    <label class="layui-form-label">文件名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="filename" lay-verify="title" autocomplete="off"
                                placeholder="请使用英文字母，不可使用特殊字符" class="layui-input" value="{{ software.filename }}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">版本号</label>
                    <div class="layui-input-block">
                        <input type="text" name="version" lay-verify="title" autocomplete="off" placeholder="软件版本号"
                                class="layui-input" value="{{ software.version }}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">文件大小</label>
                    <div class="layui-input-block">
                      <input type="text" name="size" lay-verify="title" autocomplete="off" placeholder="软件大小"
                              class="layui-input" value="{{ software.size }}">
                    </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">软件平台</label>
                  <div class="layui-input-block">
                    <input type="text" name="platform" lay-verify="title" autocomplete="off" placeholder="软件平台"
                            class="layui-input" value="{{ software.platform }}">
                  </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">文件描述</label>
                  <div class="layui-input-block">
                      <textarea placeholder="简单描述软件程序。" class="layui-textarea" name="description" >{{ software.description }}</textarea>
                  </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">下载地址</label>
                  <div class="layui-input-block">
                    <input type="text" name="url" lay-verify="title" autocomplete="off" placeholder="下载地址"
                            class="layui-input" value="{{ software.url }}">
                  </div>
                </div>
      
                <div class="layui-form-item">
                  <label class="layui-form-label">状态</label>
                  <div class="layui-input-block">
                      <input type="radio" name="enable" value="1"  title="开启" checked>
                      <input type="radio" name="enable" value="0"  title="关闭" >
                  </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">发布日期</label>
                  <div class="layui-input-block">
                    <input type="date" name="upload_time" lay-verify="title" autocomplete="off" placeholder="发布日期"
                            class="layui-input" value="{{ software.upload_time | safe }}">
                    <script>
                      // 设置upload_time为默认当前日期
                      //document.querySelector('input[name="upload_time"]').value = new Date().toISOString().slice(0,10);
                    </script>
                  </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">下载次数</label>
                  <div class="layui-input-block">
                    <input type="number" name="count" lay-verify="title" autocomplete="off" placeholder="下载次数"
                            class="layui-input" value="{{ software.count }}">
                  </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="software-update">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
{% include 'system/common/footer.html' %}
<script>
    layui.use(['form', 'jquery'], function () {
      let form = layui.form
      let $ = layui.jquery
      
      // let MODULE_PATH = '/admin/system/software/'
      let MODULE_PATH = "{{ url_for('system.software.main') }}"
      form.on('submit(software-update)', function (data) {
        let loading = layer.load()
        let formData = data.field;
        $.ajax({
          url: MODULE_PATH + 'update',
          data: JSON.stringify(data.field),
          dataType: 'json',
          contentType: 'application/json',
          type: 'post',
          success: function (result) {
            layer.close(loading)
            if (result.success) {
              layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
                parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
                parent.layui.table.reload('software-dataTable')
              })
            } else {
              layer.msg(result.msg, { icon: 2, time: 1000 })
            }
          }
        })
        // console.log(data.field)
        return false
      })
    })
  </script>
</body>
</html>